﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;//Add Ref.
using System.IO;//Add Ref

namespace Day2
{
    public partial class NotepadPage : PhoneApplicationPage
    {
        public NotepadPage()
        {
            InitializeComponent();
        }

        private void bntSave_Click(object sender, System.Windows.RoutedEventArgs e)
        {
			/* Save with Stream
        	// TODO: Add event handler implementation here.
			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
			//if(isf.FileExists("note.txt"))
			IsolatedStorageFileStream s = isf.CreateFile("note.txt");
			//isf.OpenFile("",FileMode.Open);
			StreamWriter w = new StreamWriter(s);
			w.Write(txtBody.Text);
			w.Close();
			*/
			
			IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
			setting.Add("note.dat",txtBody.Text);
			setting.Add("color","blue");
			setting.Add("datetime","10/20/2012");
			setting.Save();
        }

        private void bntLoad_Click(object sender, System.Windows.RoutedEventArgs e)
        {
			/* Load with Stream
        	// TODO: Add event handler implementation here.
			IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
			IsolatedStorageFileStream s = isf.OpenFile("note.txt",FileMode.Open);
			StreamReader r = new StreamReader(s);
			txtBody.Text = r.ReadToEnd();
			r.Close();
			*/
			IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
			if(setting.Contains("note.dat")){
				txtBody.Text =	(string) setting["note.dat"];
				//Student s = (Student) setting["std_001"];
				App a = App.Current as App;
				txtBody.Text +=	a.MyData;
				//a.MyData = "bbbb";
			}
        }
    }
}
